{{ define "admin/manager/add.html" }}
{{ template "layouts/header.html" }}
<body style="background-color: #FFFFFF">
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">用户昵称</label>
        <div class="layui-input-inline">
            <input type="text" name="username" lay-verify="required" placeholder="请输入用户昵称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password" lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">所属权限组</label>
        <div class="layui-input-inline">
            <select name="role_id" lay-verify="required"  lay-search="">
                <option value="">请选择</option>
                {{ range $key,$value := .roleList }}
                <option value="{{$value.id}}">{{$value.title}}</option>
                {{ end }}
            </select>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">用户状态</label>
        <div class="layui-input-inline">
            <input type="checkbox" lay-verify="required" lay-filter="status" name="status" value="1" lay-skin="switch" lay-text="开启|关闭" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-inline">
            <input type="text" name="mobile" lay-verify="required" placeholder="请输入手机" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-inline">
            <input type="text" name="email" lay-verify="required" placeholder="请输入邮箱" value="test@qq.com" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="submit" id="layuiadmin-app-form-submit" value="确认添加">
    </div>
</div>
<script>
    layui.use(['layer','index','form'], function(){
        var $ = layui.$
            ,form = layui.form
            ,layer = layui.layer;


        //事件-提交
        form.on('submit(submit)', function(data){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            //提交 Ajax 成功后，关闭当前弹层并重载表格
            $.ajax({
                url:"/admin/manager/doadd",
                method: "POST",
                data: data.field,
                success: function(res) {
                    if(res.code == 0){
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1500,
                        },function () {
                            parent.layui.table.reload('table-index'); //重载表格
                            parent.layer.close(index); //再执行关闭
                        });
                    } else {
                        layer.msg(res.msg, {
                            icon: 5,
                            time: 1500
                        });
                    }
                },
                error: function() {
                    layer.msg("添加失败");
                }
            });
        });

        /* 事件-指定开关 */
        form.on('switch(status)', function(obj){
            obj.elem.value = this.checked ? 1 : 0
            form.render();
        });
    })
</script>
</body>
{{ end }}